home *** CD-ROM | disk | FTP | other *** search
- unit ShellIconU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls;
-
- type
- TMainForm = class(TForm)
- dlgOpen: TOpenDialog;
- imgSmall: TImage;
- imgLarge: TImage;
- imgSelected: TImage;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- btnChooseFile: TButton;
- lblDisplayName: TLabel;
- lblFileType: TLabel;
- lblExeType: TLabel;
- procedure btnChooseFileClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- MainForm: TMainForm;
-
- implementation
-
- {$R *.DFM}
-
- uses
- ShellAPI, ShlObj;
-
- procedure TMainForm.btnChooseFileClick(Sender: TObject);
- var
- FI: TSHFileInfo;
- ExeType: DWord;
- const
- MZ = $5A4D; //"MZ"
- NE = $504E; //"NE"
- PE = $4550; //"PE"
- begin
- if dlgOpen.Execute then
- begin
- //Get display name and type description
- SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
- SHGFI_DISPLAYNAME or SHGFI_TYPENAME);
- lblDisplayName.Caption := FI.szDisplayName;
- lblFileType.Caption := FI.szTypeName;
-
- //Get EXE type
- ExeType := SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI, SizeOf(FI),
- SHGFI_EXETYPE);
- if ExeType = MZ then
- lblExeType.Caption := 'MS-DOS .EXE, .COM or .BAT file'
- else
- if ExeType = PE then
- lblExeType.Caption := 'Win32 console application'
- else
- if ((LoWord(ExeType) = NE) or
- (LoWord(ExeType) = PE)) and
- ((HiWord(ExeType) = $0300) or
- (HiWord(ExeType) = $0350) or
- (HiWord(ExeType) = $0400)) then
- lblExeType.Caption := 'Windows application'
- else
- lblExeType.Caption := 'Not an executable file';
-
- //Get large icon
- SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
- SizeOf(FI), SHGFI_ICON or SHGFI_LARGEICON);
- imgLarge.Picture.Icon.Handle := FI.hIcon;
-
- //Get small icon
- SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
- SizeOf(FI), SHGFI_ICON or SHGFI_SMALLICON);
- imgSmall.Picture.Icon.Handle := FI.hIcon;
-
- //Get selected icon
- SHGetFileInfo(PChar(dlgOpen.FileName), 0, FI,
- SizeOf(FI), SHGFI_ICON or SHGFI_SELECTED);
- imgSelected.Picture.Icon.Handle := FI.hIcon;
- end
- end;
-
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- btnChooseFile.Click
- end;
-
- end.
-